﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Data;
using ScrumTable.Common.Logging;
using ScrumTable.Common.Net;
using ScrumTable.Common.Security;
using ScrumTable.Common.Threading;
using ScrumTable.DL.Data.Generic.Cache;
using ScrumTable.DL.Data.Schema;
using ScrumTable.DL.Data.Schema.ScrumTableV1;
using ScrumTable.DL.Data.TFS.Bulk.Properties;
using ScrumTable.DL.Data.TFS.Services.TeamFoundation;
using ScrumTable.DL.Data.TFS.Services.TeamFoundation.Utils;

#endregion

namespace ScrumTable.DL.Data.TFS.Bulk.Services
{
    /// <summary>
    /// This class is used to initiate the connection and load all needed
    /// information to access data on the project level.
    /// </summary>
    internal partial class ConnectionCacheLoader
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        partial void LoadMemberList(
            ref IList<CacheTeam> teamListToInit,
            ref IList<CacheMember> memberListToInit,
            TfsServerWrapper tfsInstance,
            CacheContext dataContext,
            Project project)
        {
            ICollection<TeamFoundationIdentity> identities = MemberLoader.GetMembers(GetAssignedToValues(project));
            memberListToInit = new List<CacheMember>(identities.Count);
            double orderIndex = 0;

            foreach (TeamFoundationIdentity identity in identities)
            {
                memberListToInit.Add(
                    dataContext.ElementFactory.CreateMember(
                        ++orderIndex,
                        identity.DisplayName,
                        identity.GetAttribute(IdentityAttributeTags.MailAddress, string.Empty),
                        identity.GetAttribute(IdentityAttributeTags.AccountName, string.Empty),
                        identity.GetAttribute(IdentityAttributeTags.Domain, string.Empty),
                        identity.GetUniqueId(),
                        _connectionCtx.Contains(identity.GetUniqueId()), 
                        null)
                    );
            }
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}